Wiki

Clone wiki

beremiz / Build minimal Beremiz runtime with Buildroot

Intro

This article will describe how to create the minimal GNU/Linux image with Beremiz runtime. For that purpose Buildroot will be used. All steps are done on GNU/Linux machine. It's expected that make, gcc, g++, autotools and other tools usually needed to build software for host machine are installed. On Debian-based system (like Ubuntu) this can be done by installing 'build-essentials' package.

Base setup

  1. Create directory, where all work will be done
#!shell
$ mkdir beremiz_image
  1. Clone Buildroot repository
#!shell
$ cd beremiz_image && git clone git://git.buildroot.net/buildroot

Next steps will describe buildroot configuration. Image will be build for x86 architecture, default kernel configuration from upstream is used and rootfs is packaged into cpio. All this configuration can be easily tested on host machine using qemu.

Overlay for rootfs

Overlay are files that are copied into target image. Overlay will contain Beremiz_service and some requirements that are missing in buildroot currently.

#!shell
$ cd ..
$ mkdir beremiz_overlay
  • Add minimal set of files needed to run only Beremiz_service.py
#!shell
$ cd beremiz_overlay && mkdir root && cd root
$ wget https://bitbucket.org/automforge/beremiz/get/tip.tar.bz2
$ tar -xv --wildcards --no-wildcards-match-slash -f tip.tar.bz2 '*/Beremiz_service.py' '*/runtime' '*/util/' '*/version.py'
$ rm tip.tar.bz2
$ mv * beremiz
$ cd ../

This is the set of files required by Beremiz_service.py.

#!
$ find
.
./runtime
./runtime/xenomai.py
./runtime/loglevels.py
./runtime/NevowServer.py
./runtime/WampClient.py
./runtime/__init__.py
./runtime/webinterface.js
./runtime/PLCObject.py
./runtime/ServicePublisher.py
./runtime/typemapping.py
./util
./util/__init__.py
./util/paths.py
./version.py
./Beremiz_service.py
  • Add missing in buildroot python zeroconf package
#!shell
$ mkdir -p usr/lib/python2.7/site-packages && usr/lib/python2.7/site-packages
$ wget -O zeroconf.tar.gz https://files.pythonhosted.org/packages/bf/e3/acc6e2c2938428afa2450143fc4d3953ec60cb4d859db3a58f03d149ef04/zeroconf-0.19.1.tar.gz
$ tar --wildcards --no-wildcards-match-slash --strip=1 -xvf zeroconf.tar.gz  '*/zeroconf.py'
$ rm zeroconf.tar.gz
$ cd ../../../../

Buildroot configuration

  • Create file named 'beremiz_i386_defconfig' in beremiz_image directory with following content
#!
BR2_x86_nocona=y
BR2_TOOLCHAIN_BUILDROOT_GLIBC=y
BR2_KERNEL_HEADERS_4_17=y
BR2_SYSTEM_DHCP="eth0"
BR2_ROOTFS_OVERLAY="../beremiz_overlay"
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_USE_ARCH_DEFAULT_CONFIG=y
BR2_PACKAGE_PYTHON=y
BR2_PACKAGE_PYTHON_AUTOBAHN=y
BR2_PACKAGE_PYTHON_ENUM34=y
BR2_PACKAGE_PYTHON_NETIFACES=y
BR2_PACKAGE_PYTHON_PYRO=y
BR2_TARGET_ROOTFS_CPIO=y
  • Build rootfs image.

#!
make defconfig BR2_DEFCONFIG=../beremiz_i386_defconfig
make -j$(nproc)
This will take time, because cross-toolchain, kernel and all corresponding software will be downloaded and build from source. At the end

  • Check size of generated image
    #!
    $ ls -lh output/images/
    total 44M
    -rw-r--r-- 1 developer developer 6.9M Jul 24 16:52 bzImage
    -rw-r--r-- 1 developer developer  18M Jul 24 16:52 rootfs.cpio
    -rw-r--r-- 1 developer developer  19M Jul 24 16:52 rootfs.tar
    

Run generated image

#!
qemu-system-i386 -enable-kvm -nic user,hostfwd=tcp::3000-:3000 -initrd output/images/rootfs.cpio -kernel output/images/bzImage -no-reboot -serial stdio -display none --append 'console=ttyS0,115200'

Beremiz_service isn't started automatically. To start it run following commands:

#!
Welcome to Buildroot
buildroot login: root
# cd beremiz
# ./Beremiz_service.py -t 0 -x 0 -a 1
Pyro port : 3000
Current working directory : /root/beremiz

Connect to running Beremiz_service

qemu-system-i386 command used in previous step forwards connection to TCP port 3000 on host to port 3000 on guest. It makes possible to connect to Beremiz_service running inside guest system from host system. Open Beremiz IDE on host machine. Open for example 'first_steps' project and set URI_location to point to 'PYRO://127.0.0.1:3000'. If your host system is 64-bit architecture, then you have to set CFLAGS and LDFLAGS to generate 32-bit code, because guest system is 32-bit.

Project settings are displayed below. Screenshot from 2018-07-24 17-36-53.png

Beremiz_service log during connection from host Beremiz IDE:

# ./Beremiz_service.py -t 0 -x 0 -a 1
[   24.573888] random: python: uninitialized urandom read (2500 bytes read)
[   24.592664] random: python: uninitialized urandom read (2500 bytes read)
Pyro port : 3000
Current working directory : /root/beremiz
PLCobject : NewPLC (9d6123759abd9a3da3c94c43b8dcbbc2)
PLCobject : PLC started
PLCobject : PLC stopped

Updated